<template>
  <div class="app-container">
      <el-row>
  <el-col :span="22">
    
     <el-form ref="filterForm" :model="filterForm" :inline="true" label-position="left" label-width="100px">
        <el-form-item label="合约" prop="symbol">
          <el-input v-model="filterForm.symbol" clearable placeholder="合约" style="width: 200px;" class="filter-item" @input="handleFilter" @keyup.enter.native="handleFilter" />
        </el-form-item>
        <el-form-item label="周期" prop="scale">
          
      <el-radio-group v-model="filterForm.scale" @input="handleFilter">
        <el-radio-button label="1">M1</el-radio-button>
        <el-radio-button label="1440">D1</el-radio-button>
      </el-radio-group>
        </el-form-item>
      </el-form>
  </el-col>
  <el-col :span="2">
    <el-button type="primary" @click="handleFilter">刷新</el-button>
  </el-col>
</el-row>
      <el-row>
  <el-col :span="12">
      <el-table
      :data="signalList"
      border
      style="width: 100%">
      <el-table-column
        prop="cycle"
        label="时间"
        width="140">
      </el-table-column>
      <el-table-column
        prop="symbol"
        label="合约">
      </el-table-column>
      <el-table-column
        label="方向"
        width="100">
        <template slot-scope="{row}">
          <span v-if="row.direction == 1" style="color:red;">多</span>
          <span v-else-if="row.direction == 2" style="color:green;">空</span>
          <span v-else style="color:green">未明确</span>
        </template>
      </el-table-column>
      <el-table-column
        label="方向"
        width="100">
        <template slot-scope="{row}">
          <span v-if="row.lDirection == 1" style="color:red;">多</span>
          <span v-else-if="row.lDirection == 2" style="color:green;">空</span>
          <span v-else style="color:green">未明确</span>
        </template>
      </el-table-column>
      <el-table-column
        label="摆动"
        width="200">
        <template slot-scope="{row}">
          <span>{{ row.signal }}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="createdAt"
        label="创建时间"
        width="160">
      </el-table-column>
      </el-table>
  </el-col>
  <el-col :span="12">
      <el-table
      :data="quoteList"
      border
      style="width: 100%">
      <el-table-column
        prop="cycle"
        label="时间"
        width="140">
      </el-table-column>
      <el-table-column
        prop="symbol"
        label="合约">
      </el-table-column>
      <el-table-column
        label="开盘价"
        width="100">
        <template slot-scope="{row}">
          <span v-if="row.lDirection == 1" style="color:red;">多</span>
          <span v-else-if="row.lDirection == 2" style="color:green;">空</span>
          <span v-else style="color:green">未明确</span>
        </template>
      </el-table-column>
      <el-table-column
        label="收盘价"
        width="200">
        <template slot-scope="{row}">
          <span>{{ row.signal }}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="createdAt"
        label="创建时间"
        width="160">
      </el-table-column>
      </el-table>
  </el-col>
</el-row>
      
    
    <pagination v-show="total>0" :total="total" :page.sync="filterForm.page" :limit.sync="filterForm.size" @pagination="getList" />

  </div>
</template>

<script>
//import { getFaultinessList,  removeFaultinessByID, changeFaultinessStatusByID } from '@/api/development/faultiness'
import waves from '@/directive/waves' // waves directive
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import {getSymbol} from '@/utils/symbol' // secondary package based on el-pagination
import {getPolicyList} from '@/api/strategy/policy'
import {getQuotationList} from '@/api/strategy/quotation'
export default {
  name: 'faultinessAdmin',
  components: { Pagination },
  directives: { waves },
  filters: {
  },
  data() {
    return {
      
      socket:"",
      tableKey: 0,
      dataType:"1",
      windowHeight:"800",
      allowedLoaded:false,
      allowedLoadedRealtime:false,
      signalFilterForm:{},
      symbolList:[],
      policyList:[],
      quoteList:[],
      signalList:[],
      purchaseList:[],
      contractList: [
      ],
      total: 0,
      listLoading: false,
      connected:"loading",
      realtimeSetting:{
        scale:1,
        symbol:"i2309"
      },
      positionForm:{
        localSymbol:"i",
        status:10,
        siminute:2
      },
      filterForm: {
        page: 1,
        size: 10,
        scale:1,
        symbol:''
      }
    }
  },
  created() {
    let symbolData = window.localStorage.getItem('localSymbol')
    symbolData = JSON.parse(symbolData)
    try {
      this.localSymbol = symbolData.code
    } catch (error) {
      
    }
    this.filterForm.symbol = this.$route.query && this.$route.query.symbol
    let dateHandle = new Date()
    this.filterForm.beginDate = dateHandle.getFullYear()+"-"+(dateHandle.getMonth()+1)+"-"+dateHandle.getDate()
    this.getList(true)
  },
  destroyed(){
  },
  methods: {
    tableRowClassName({row, rowIndex}) {
      if (row.direction == 2) { // 假设你想要设置第二行的背景色
        return 'row-background-sell';
      }
      if (row.direction == 1) { // 假设你想要设置第二行的背景色
        return 'row-background-buy';
      }
      return 'row-background-empty';
    },
    getList:function(){
      let _this = this;
      console.log("期权",_this.filterForm)
      getPolicyList(_this.filterForm).then((response) => {
        console.log("getPolicyList",response)
          if (response.code === 200) {
            this.signalList = response.data.list
            this.total = response.data.total
          } else {
            _this.$message({
              message: response.msg,
              type: 'error'
            })
          }
      })
      this.refreshQuotationList()
    },
    refreshQuotationList:function(){
      let _this = this;
      console.log("期权",_this.filterForm)
      getQuotationList(_this.filterForm).then((response) => {
        console.log("getQuotationList",response)
          if (response.code === 200) {
            this.quoteList = response.data.list
            this.total = response.data.total
          } else {
            _this.$message({
              message: response.msg,
              type: 'error'
            })
          }
      })
    },
    handleFilter() {
      this.filterForm.page = 1
      this.getList()
    }
  }
}
</script>
<style>
.row-background-sell {
  background-color: #90EE90!important;
  color: #fff;
}
.row-background-buy {
  background-color: #FFC0CB!important; 
  color:#fff;
}
</style>